#!/usr/bin/env/python3
# -*- coding: utf-8 -*-

"""
@Time    : 2020/3/14 19:55
@Author  : Chen Liu
@FileName: str.py
@Software: PyCharm
"""


def swap(str_1, str_2, str_list, m):
    for k in range(1, m):
        new_str_1 = str_1[:k] + str_2[k:]
        if new_str_1 not in str_list:
            str_list.append(new_str_1)
        new_str_2 = str_2[:k] + str_1[k:]

        if new_str_2 not in str_list:
            str_list.append(new_str_2)

    return str_list


def count_str():
    n, m = [int(x) for x in input().split()]
    str_list = []
    for i in range(n):
        str_list.append(input())

    for i in range(n):
        for j in range(i+1, n):
            str_1 = str_list[i]
            str_2 = str_list[j]
            for k in range(1, m):
                new_str_1 = str_1[:k] + str_2[k:]

                if new_str_1 not in str_list:
                    str_list.append(new_str_1)

                new_str_2 = str_2[:k] + str_1[k:]

                if new_str_2 not in str_list:
                    str_list.append(new_str_2)

                str_list = swap(str_1, str_2, str_list, m)
                print(str_list)

    print(str_list)
    return len(str_list)


if __name__ == "__main__":
    count = count_str()
    print(count)
